<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <title>Document</title>
  <script src="https://cdn.jsdelivr.net/npm/vue@2.7.10/dist/vue.js"></script>
</head>

<body>
  <div id="app">
    <h2>{{name}}</h2>
    <h2>{{num}}</h2>
    <button @click="num++">+1</button>
    <hr>
    <h2>{{info.child.age}}</h2>
    <button @click="info.child.age++">+1</button>
  </div>

  <script>
    let vm = new Vue({
      el: "#app",
      data() {
        return {
          name: "码路",
          num: 100,
          info: {
            name: "ml",
            age: 18,
            child: {
              name: "wc",
              age: 20
            }
          }
        }
      },
      watch: {
        num(newNum, oldNum) {
          console.log(newNum, oldNum);
        },
        // info(newInfo, oldInfo) {
        //   console.log(newInfo, oldInfo);
        // },
        // info: {
        //   // 这样写不推荐
        //   deep: true,
        //   handler(newInfo, oldInfo) {
        //     console.log(newInfo, oldInfo);
        //   }
        // },
        "info.child.age"(newAge, oldAge) {
          console.log(newAge, oldAge);
        }
      }
    });
  </script>
</body>

</html>